package com.example.yuejian.yuejian.activity;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import com.example.yuejian.yuejian.R;
import com.example.yuejian.yuejian.adapter.MyPrizeAdapter;
import com.example.yuejian.yuejian.base.BaseActivity;
import com.example.yuejian.yuejian.base.ModleListListener;
import com.example.yuejian.yuejian.bean.MyPrize;
import com.example.yuejian.yuejian.model.UserModel;

import java.util.List;

public class MyPrizeActivity extends BaseActivity {

    private RecyclerView recyclerView;
    private  ImageView btn_back;
    List<MyPrize> list;
    private ModleListListener<MyPrize> modleListListener=new ModleListListener<MyPrize>() {
        @Override
        public void onResponse(List<MyPrize> l) {
            list=l;
            recyclerView.setAdapter(new MyPrizeAdapter(getApplication(),list));

        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(getApplication(),"fail:"+msg,Toast.LENGTH_SHORT).show();
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_prize);
        initViews();
        getData();
        back();
    }

    private void initViews()
    { recyclerView=(RecyclerView)findViewById(R.id.my_prize_recycleview);
        // GridLayoutManager gm = new GridLayoutManager(this.getActivity(),2);
        // 网格是的list布局   2列
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        //recyclerView.setLayoutManager(gm);

    }
    private  void getData()
    {
        UserModel userModel=new UserModel();
      userModel.myPrizeList(getUser_id(),modleListListener);
    }
    private void back()
    {
        btn_back=(ImageView)findViewById(R.id.imgBtn_myprize_back);
        btn_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

    }
}
